package cn.bincker.mycaptcha.letter;

import cn.bincker.mycaptcha.VerifyRequestAnswerResolver;
import cn.bincker.mycaptcha.basic.exception.CaptchaVerifyFailException;
import cn.bincker.mycaptcha.letter.entity.LetterAnswer;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;

public class LetterVerifyRequestAnswerResolver implements VerifyRequestAnswerResolver<LetterAnswer> {
    @Override
    public LetterAnswer resolver(HttpServletRequest request) {
        var answer = request.getParameter("captcha_code");
        if(!StringUtils.hasText(answer)) throw new CaptchaVerifyFailException();
        return new LetterAnswer(answer);
    }
}
